<?php

use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model common\models\HyBook */

$this->title = '新建资源';
$this->params['breadcrumbs'][] = ['label' => '资源管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hy-book-create">

    <?= $this->render('_form_' . $type, [
        'model' => $model,
    ]) ?>

</div>
<script>
    <?php $this->beginBlock('js_block') ?>

    $(".cat_id_input > select").change(function () {
        let cateId = $(this).val();//获取一级目录的值
        $(".cat_id2_input").find('select').html("<option value=''>请选择分类</option>");
        if (cateId > 0) {
            getCourse(cateId);//查询二级目录的方法
        }
    });

    function getCourse(cateId) {

        $.ajax({
            type: "GET",
            url: '<?=Url::toRoute('option')?>',
            data: {id: cateId},
            dataType: 'json'
        })
            .done(function (msg) {
                console.log(msg);
                if (msg['status'] == 200) {
                    $(".cat_id2_input").find('select').html(msg['data']);
                }
            });
    }

    <?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_block'], \yii\web\View::POS_END); ?>
